<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>vue 组件</title>
    <script src="./vue.js"></script>
   
</head>
<body>
    <div id="app">
        <counter ref="one" :count="2" @change="handleChange"></counter>
        <counter ref="two" :count="3" @change="handleChange"></counter>
        <div>{{total}}</div>
    </div>
    <script>
        Vue.component('counter',{
            props: ['count'],
            template: `<div @click="handleClick">{{number}}</div>`,
            data: function(){
                return {
                    number: this.count
                }
            },
            methods: {
                handleClick: function() {
                    this.number ++ 
                    this.$emit("change")
                }
            }
        })
        var vm = new Vue({
            el: '#app',
            data: {
              total: 0
            },
            //方法
            methods:{
                handleChange: function(){
                    this.total = this.$refs.one.number + this.$refs.two.number
                }
            },
            //组件
            components: {
                
            },
            //计算属性
            computed:{
               
            }


        })
    </script>
</body>
</html>